<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" 
	xmlns:pe="http://primefaces.org/ui/extensions"
	template="/WEB-INF/templates/template.xhtml">
	
	<ui:define name="headIncludes">
		<f:event listener="#{contaPagarBean.initializeForm(param.contaPagarId)}" type="preRenderView"/>
	</ui:define>
	
	<ui:define name="pageName">Detalhe de Conta a Pagar</ui:define>
	<ui:define name="buttons">
		<p:commandButton value="Pagar a conta" style="height:28px;" action="#{contaPagarBean.changeToPagarConta}" rendered="#{contaPagarBean.currentConta.status == 'PENDENTE'}" icon="ui-icon-check"/>
		<p:commandButton value="Cancelar a conta" style="height:28px;" actionListener="#{contaPagarBean.openDialogCancelarContaPagar}" 
			rendered="#{contaPagarBean.currentConta.status == 'PENDENTE' and contaPagarBean.currentConta.compra == null}" icon="ui-icon-cancel"/>
		<p:commandButton value="Voltar" style="height:28px;" action="#{contaPagarBean.changeToList}" process="@this" icon="ui-icon-arrowreturnthick-1-w"/>			
	</ui:define>
	
	<ui:define name="content">	
		<p:panel>
			<div>
				<p:messages autoUpdate="true" id="messageDetailConta" closable="true"/>
				
				<h:panelGrid columns="1" style="padding:5px;">
					<h:outputText style="font-weight:bold;padding:7px;" value="Status: #{contaPagarBean.currentConta.status}" />
				</h:panelGrid>
				
				<h:panelGrid columns="1" style="padding:5px;">
					<h:outputText style="font-weight:bold;padding:7px;" value="Fornecedor" />
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.fornecedor.nome}"/>
				</h:panelGrid>
								
				<h:panelGrid columns="5" style="padding:5px;" rendered="#{contaPagarBean.currentConta.descricao != null}">
					<h:outputText style="font-weight:bold;padding:7px;" value="Nº do documento" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Descrição" />				
					<h:outputText style="font-weight:bold;padding:7px;" value="Data de emissão" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Valor" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Data de vencimento" />
					
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.id}"/>	
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.descricao}" />
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.dataEmissao}">
						<f:convertDateTime pattern="dd/MM/yyyy"/>
					</h:outputText>
					<h:outputText  style="padding:7px;" value="#{contaPagarBean.currentConta.valor}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
					</h:outputText>
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.dataVencimento}">
						<f:convertDateTime pattern="dd/MM/yyyy"/>
					</h:outputText>
				</h:panelGrid>
				
				<h:panelGrid columns="6" style="padding:5px;" id="panelPagamento">
					<h:outputText style="font-weight:bold;padding:7px;" value="Multa (R$)" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Juros (%)" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Desconto (R$)" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Desconto (%)" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Data de pagamento" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Valor pago" rendered="#{contaPagarBean.currentConta.status == 'PAGA'}"/>
					<h:outputText style="font-weight:bold;padding:7px;" value="Valor total" rendered="#{contaPagarBean.currentConta.status != 'PAGA'}"/>
					
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.multa}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
					</h:outputText>
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.juros}">
						<f:convertNumber pattern="#,###,##0.00" />
					</h:outputText>
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.descontoValor}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
					</h:outputText>
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.descontoPercentual}">
						<f:convertNumber pattern="#,###,##0.00" />
					</h:outputText>
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.dataPagamento}">
						<f:convertDateTime pattern="dd/MM/yyyy"/>
					</h:outputText>					
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.valorPago}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
					</h:outputText>					
				</h:panelGrid>

				<h:panelGrid columns="1" style="padding:5px;" rendered="#{contaPagarBean.currentConta.condicaoPagamento != null}">
					<h:outputText style="font-weight:bold;padding:7px;" value="Condição de pagamento" />
					<h:outputText style="padding:7px;" value="#{contaPagarBean.currentConta.condicaoPagamento.condicaoPagamento}"/>
				</h:panelGrid>
			</div>
		</p:panel>		
	</ui:define>
	
	<ui:define name="popups">
		<p:dialog appendToBody="true" modal="true" closable="false" widgetVar="popupConfirmCancel"
			width="400" resizable="false" header="Confirmação" height="75">
			<h:form>
				<div style="margin-top: 10px;">
					<h:outputText value="Confirma o cancelamento da conta a pagar?"/>
				</div>
				<div align="right" style="margin-top: 15px;">
					<p:commandButton value="Confirmar" action="#{contaPagarBean.cancelarContaPagar}" oncomplete="popupConfirmCancel.hide()" icon="ui-icon-check"/>
					<p:commandButton value="Cancelar" onclick="popupConfirmCancel.hide()" icon="ui-icon-cancel"/>
				</div>		
			</h:form>			
		</p:dialog>
	</ui:define>
</ui:composition>